//
//  LandmarkList.swift
//  codelabs
//
//  Created by 雷雷 on 23/05/2025.
//

import SwiftUI

struct LandmarkList: View {
    @Environment(ModelData.self) var modelData
    @State private var showFavoriteOnly = false
    
    var filteredMask:[Landmark]{
        modelData.landmarks.filter{landmark in
            (!showFavoriteOnly||landmark.isFavorite)
        }
    }
    
    var body: some View {
        List{
            Toggle(isOn:$showFavoriteOnly){
                Text("Favorite only")
            }.padding()
            
            ForEach(filteredMask){item in
                
                NavigationLink{
                    LandmarkDetail(landmark:item)
                }label: {
                    LandmarkRow(landmark: item)
                }
            }
        }
        .animation(.default,value:filteredMask)
    }
    
}

#Preview {
    LandmarkList()
        .environment(ModelData())
}
